package cn.fangline.wo.task.akka.mailbox;

import akka.actor.ActorSystem;
import akka.actor.PoisonPill;
import akka.dispatch.PriorityGenerator;
import akka.dispatch.UnboundedPriorityMailbox;
import cn.fangline.wo.task.akka.messages.AgentHousePage;
import cn.fangline.wo.task.akka.messages.CheckAlive;
import com.typesafe.config.Config;


/**
 * Created by shann on 17/6/5.
 */
public class HouseGrabSuperiorUnboundedPriorityMailbox extends UnboundedPriorityMailbox {

    public HouseGrabSuperiorUnboundedPriorityMailbox(ActorSystem.Settings settings, Config config) {

        // Creating a new PriorityGenerator,
        super(new PriorityGenerator() {
            @Override
            public int gen(Object message) {
                if (message instanceof CheckAlive) {
                    // treated with highest priority
                    return 0;
                }
                else if(message instanceof Integer){
                    return 2;
                }
                else if(message instanceof Boolean){
                    return 3;
                }
                else if(message instanceof AgentHousePage){
                    return 1;
                }
                else if (message.equals(PoisonPill.getInstance()))
                    // PoisonPill when no other left
                    return 5;
                else
                    // By default they go with medium priority
                    return 6;
            }
        });
    }
}
